package com.springboot.web;

import com.springboot.model.Student;
import javafx.scene.chart.ValueAxis;
import org.springframework.web.bind.annotation.*;

import java.util.HashMap;
import java.util.Map;

@RestController
public class StudentController {

    @RequestMapping(value = "/student")
    public Object student(Integer id,Integer age){
        Student student = new Student();
        student.setId(id);
        student.setAge(age);
        return  student;
    }

//    @RequestMapping(value = "/student/detail/{id}/{age}")

    @GetMapping(value = "/student/detail/{id}/{age}")
    public Object student1(@PathVariable("id") Integer id,
                           @PathVariable("age") Integer age){
        Map<String,Object> retMap = new HashMap<>();

        retMap.put("id",id);
        retMap.put("age",age);
        return retMap;
    }

//    @RequestMapping(value = "/student/detail/{id}/{age}")
    @DeleteMapping(value = "/student/detail/{id}/{age}")
    public Object student2(@PathVariable("id") Integer id,
                           @PathVariable("age") Integer age){
        Map<String,Object> retMap = new HashMap<>();

        retMap.put("id",id);
        retMap.put("age",age);
        return retMap;
    }
    //以上代码student1和student2会出现请求路径模糊
    //通常RESTful风格中请求方法会按照增删改查的请求方式来区分
    //请求路径不要出现动词，最好都是名词
    @DeleteMapping(value = "/student/{id}/detail/{city}")
    public Object student3(@PathVariable("id") Integer id,
                           @PathVariable("city") Integer city){
        Map<String,Object> retMap = new HashMap<>();

        retMap.put("id",id);
        retMap.put("city",city);
        return retMap;
    }
    //通过路径不同区分两个delete、

    @PostMapping(value = "/student/{id}")
    public Object addStudent(@PathVariable("id") Integer id){
        return "add student ID:"+id;
    }

    @PutMapping(value = "/student/{id}")
    public Object updateStudent(@PathVariable("id") Integer id){
        return "update student ID"+id;
    }
}
